/*
 * @Author: your name
 * @Date: 2021-11-03 19:40:02
 * @LastEditTime: 2022-01-03 16:10:24
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \vue-antd-admin-new\src\router\index.js
 */
import Vue from 'vue'
import Router from 'vue-router'
import {formatRoutes} from '@/utils/routerUtil'
// const originalPush = Router.prototype.push
// const originalReplace = Router.prototype.replace

// Router.prototype.push = function push(location, onResolve, onReject) {
//   if (onResolve || onReject) {
//     return originalPush.call(this, location, onResolve, onReject)
//   }
//   return originalPush.call(this, location).catch(err => err)
// }


// Router.prototype.replace = function push(location, onResolve, onReject) {
//   if (onResolve || onReject) {
//     return originalReplace.call(this, location, onResolve, onReject)
//   }
//   return originalReplace.call(this, location).catch(err => err)
// }

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}                     //多次跳转报错隐藏
Vue.use(Router)

// 不需要登录拦截的路由配置
const loginIgnore = {
  // names: ['404', '403'],      //根据路由名称匹配
  // paths: ['/login'],   //根据路由fullPath匹配
  paths: ['/login','/404','/403'],   //根据路由fullPath匹配
  /**
   * 判断路由是否包含在该配置中
   * @param route vue-router 的 route 对象
   * @returns {boolean}
   */
  includes(route) {
    // console.log(route);
    // return this.names.includes(route.name) || this.paths.includes(route.path)
    return  this.paths.includes(route.path)
  }
}

/**
 * 初始化路由实例
 * @param isAsync 是否异步路由模式
 * @returns {VueRouter}
 */
function initRouter(isAsync) {
  const options = isAsync ? require('./async/config.async').default : require('./config').default
  formatRoutes(options.routes)
  return new Router({...options,
     mode:'history',base:'/property/'
     })
}



export {loginIgnore, initRouter}
